package com.ysd.twocrm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ysd.twocrm.entity.Dynamic;
import com.ysd.twocrm.mapper.DynamicMapper;
import com.ysd.twocrm.service.DynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dynamic")
public class DynamicController {
    @Autowired
    private DynamicMapper dynamicMapper;
    @Autowired
    private DynamicService dynamicService;
    /*
     * @Description 咨询师给游客留言
     * @param dm
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/5/31 16:07
     */
    @PostMapping
    public Object addDynamic(Dynamic dm){

        int insert = dynamicMapper.insert(dm);
        if(insert>0){
            return "success";
        }
        return "false";
    }
    /*
     * @Description 多条件查询留言信息
     * @param d
     * @param page
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/5/31 16:39
     */
    @GetMapping
    public Object findDynamic(Dynamic d,Integer page){


        return dynamicService.DYNAMIC_LAYUI_UTILS(d,page);
    }
    /*
     * @Description 查询当前用户留言未读总量
     * @param d
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/5/31 16:39
     */

    @GetMapping("/1")
    public Object findDynamicSum(Dynamic d){
        QueryWrapper<Dynamic> queryWrapper=new QueryWrapper<Dynamic>();
        queryWrapper.eq("userId",d.getUserId()).eq("dIsopen",1);

        return   dynamicMapper.selectCount(queryWrapper);
    }
    /*
     * @Description 设置已读未读
     * @param d
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/5/31 17:23
     */
@PutMapping
    public Object putdynamic(Dynamic d){


        int i = dynamicMapper.updateById(d);
        if(i>0){
            return "success";
        }
        return "false";
    }
    /*
     * @Description 批量删除留言
     * @param str
     * @return java.lang.Object
     * @author liusupeng
     * @date 2020/6/1 16:35
     */
    @DeleteMapping
    public Object delDynamic(String str){

        String[] split = str.split(",");
         for(int i=0;i<split.length;i++){
             dynamicMapper.deleteById(split[i]);
         }
        return "success";
    }
}
